//
//  TodayCell.m
//  RomensBI
//
//  Created by CcMark on 16/2/23.
//
//

#import "TendencyCell.h"
#import "ToolHelper.h"
#import "ChartModel.h"
@interface TendencyCell()<ChartViewDelegate>

@property(nonatomic,strong)UIImageView *barBackView;
@property(nonatomic,strong)UIView *chartBackView;

@end
@implementation TendencyCell
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        
        self.contentView.backgroundColor = [UIColor whiteColor];
    
        _barBackView = [[UIImageView alloc]init];
        _barBackView.translatesAutoresizingMaskIntoConstraints = NO;
        [self.contentView addSubview:_barBackView];
        _barBackView.image = [UIImage imageNamed:@"reportheader"];
        _barBackView.backgroundColor = [UIColor whiteColor];

        _chartBackView = [[UIView alloc]init];
        _chartBackView.translatesAutoresizingMaskIntoConstraints = NO;
        _chartBackView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_chartBackView];
        
        _reportIcon = [[UIImageView alloc]init];
        _reportIcon.translatesAutoresizingMaskIntoConstraints = NO;
        [_barBackView addSubview:_reportIcon];
        
        _reportName = [[UILabel alloc]init];
        _reportName.translatesAutoresizingMaskIntoConstraints = NO;
        [_barBackView addSubview:_reportName];
        _reportName.textColor = [UIColor whiteColor];
        _reportName.font = systemDetailFont;
        

        [self.contentView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_barBackView) format:@"H:|[_barBackView]|"]];
        [self.contentView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_chartBackView) format:@"H:|[_chartBackView]|"]];
        [self.contentView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_barBackView,_chartBackView) format:@"V:|[_barBackView(==35)][_chartBackView]-12-|"]];
        
        [_barBackView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_reportIcon,_reportName) format:@"H:|-15-[_reportIcon(==20)]-[_reportName]-|"]];
        [_barBackView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_reportIcon) format:@"V:[_reportIcon(==20)]"]];
        [_barBackView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_reportName) format:@"V:|[_reportName]|"]];
       
        [_barBackView addConstraint:[NSLayoutConstraint constraintWithItem:_reportIcon
                                                                    attribute:NSLayoutAttributeCenterY
                                                                    relatedBy:NSLayoutRelationEqual
                                                                       toItem:_barBackView
                                                                    attribute:NSLayoutAttributeCenterY
                                                                   multiplier:1.0
                                                                     constant:0.0]];
        

        [self InitViewLine];

    }
    return self;
}

#pragma mark 线性图
-(void)InitViewLine{

    _linechartView = [[LineChartView alloc]init];
    _linechartView.delegate = self;
    [_chartBackView addSubview:_linechartView];
    _linechartView.translatesAutoresizingMaskIntoConstraints = NO;
    
    [_chartBackView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_linechartView) format:@"H:|[_linechartView]|"]];
    [_chartBackView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_linechartView) format:@"V:|[_linechartView]|"]];

    
    _linechartView.descriptionText = @"";
    
    _linechartView.dragEnabled = YES;
    [_linechartView setScaleEnabled:YES];
    _linechartView.pinchZoomEnabled = YES;
    _linechartView.drawGridBackgroundEnabled = NO;
    
    _linechartView.xAxis.labelPosition = ChartLimitLabelPositionLeftBottom;
    _linechartView.xAxis.labelTextColor = [UIColor blackColor];
    _linechartView.xAxis.drawGridLinesEnabled = NO;
  //  _linechartView.maxVisibleValueCount = 15; // 最大显示数目
    _linechartView.xAxis.spaceBetweenLabels=1;
    
    ChartYAxis *leftAxis = _linechartView.leftAxis;
    [leftAxis removeAllLimitLines];
//    [leftAxis addLimitLine:ll1];
//    [leftAxis addLimitLine:ll2];
//    leftAxis.customAxisMax = 220.0;
//    leftAxis.customAxisMin = 0;
//    leftAxis.startAtZeroEnabled = NO;
//    leftAxis.gridLineDashLengths = @[@5.f, @5.f];
//    leftAxis.drawLimitLinesBehindDataEnabled = YES;
    
    _linechartView.rightAxis.enabled = YES;
    _linechartView.rightAxis.labelTextColor = [UIColor clearColor];
    
    [_linechartView.viewPortHandler setMaximumScaleY: 2.f];
    [_linechartView.viewPortHandler setMaximumScaleX: 2.f];
    
    _linechartView.legend.form = ChartLegendFormLine;
    
    [_linechartView animateWithXAxisDuration:2.5 easingOption:ChartEasingOptionEaseInOutQuart];
    
}


@end
